package com.example.music.ui.music;

import android.util.Log;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.music.entity.DataBanner;
import com.example.music.entity.DataMusic;
import com.example.music.entity.RequestFilter;
import com.example.music.entity.RequestUp;
import com.example.music.network.Api;
import com.example.music.network.RetrofitBase;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MusicViewModel extends ViewModel {

    private MutableLiveData<List<DataMusic>> dataMusic;

    public MusicViewModel() {
        dataMusic = new MutableLiveData<>();
        setFilter("治愈");
    }
    public void setFilter(String type){
        type = type.replaceAll(" ","");
        Log.d("TAG", "setFilter1: " +type);
        Api.bannerService service = RetrofitBase.getService(Api.bannerService.class);
        service.dataFilter(new RequestFilter(type)).enqueue(new Callback<DataBanner<List<DataMusic>>>() {
            @Override
            public void onResponse(Call<DataBanner<List<DataMusic>>> call, Response<DataBanner<List<DataMusic>>> response) {
                Log.d("TAG", "setFilter2: " +response.body().data);
                dataMusic.setValue(response.body().data);
            }

            @Override
            public void onFailure(Call<DataBanner<List<DataMusic>>> call, Throwable throwable) {

            }
        });
    }
    public LiveData<List<DataMusic>> getText() {
        return dataMusic;
    }
}